extends Node
class_name MushroomSeat


# 内部函数
var is_seat_taken: bool = false 
var is_seat_booked: bool = false

# 引用函数
var woodstack: WoodStackLogic
var on_seat_mushroom: MushroomLogic = null
var booker_mushroom: MushroomLogic

# 信号
signal mushroom_is_seated(mushroom: Node)
signal mushroom_is_removed(removed_mushroom: Node)
signal seat_stat_changed()

# 初始化
func _ready():
	woodstack.seat_booked_by_mushroom.connect(_on_seat_booked)
	return


# 当座位被预订时
func _on_seat_booked(mushroom, seat):
	if seat == self:
		is_seat_taken = true
		mushroom.mushroom_removed.connect(_on_mushroom_remove)
		
# 木桩等待磨菇坐好后，才发送参数信号通知木桩计算产出数据
func on_mushroom_seating(current_mushroom):
	mushroom_is_seated.emit(current_mushroom)
	current_mushroom.set_mushroom_stat_seating()
	on_seat_mushroom = current_mushroom
	
# 当磨菇被移除时
func _on_mushroom_remove(removed_mushroom):
	if removed_mushroom.mushroom_removed.is_connect(removed_mushroom):
		removed_mushroom.mushroom_removed.disconnect(removed_mushroom)
		is_seat_booked = false
	seat_stat_changed.emit()


	
	
